package chapter0;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
public class MainApp {
    public void validateBeans() {
        System.out.println("Here we are in Beans factory!");
        XmlBeanFactory factory = new XmlBeanFactory
                (new ClassPathResource("Beans.xml"));
        HelloWorld obj = (HelloWorld) factory.getBean("bean1");
        obj.getMessage();

        HelloWorld objA = (HelloWorld) factory.getBean("bean2");
        objA.setMessage("I am object A in Bean factory!");
        objA.getMessage();

    }
    public void validateApplicationContext() {
        System.out.println("Here we are in Application Context!");
        ApplicationContext context =
                new ClassPathXmlApplicationContext("Beans.xml");
        HelloWorld obj = (HelloWorld) context.getBean("bean1");

        obj.getMessage();

        HelloWorld objA = (HelloWorld) context.getBean("bean1");
        objA.setMessage("I am object A in ApplicationContext!");
        objA.getMessage();
    }
    public static void main(String[] args) {
        MainApp obj = new MainApp();
        obj.validateBeans();
        obj.validateApplicationContext();
    }
}
